package pt.isec.a21210392.a21190220.ludotwist.GameLogic;

import pt.isec.a21210392.a21190220.ludotwist.R;

public class GoToEndHouse extends House
{
	private static final long serialVersionUID = 1L;
	private String color;
	private int redPinImage;
	private int bluePinImage;
	private int greenPinImage;
	private int yellowPinImage;
	private int redSuperPinImage;
	private int blueSuperPinImage;
	private int greenSuperPinImage;
	private int yellowSuperPinImage;

	public GoToEndHouse(int number, int line, int column, String color)
	{
		super(number, color.equals("RED") ? R.drawable.almost_finish_red: color.equals("YELLOW") ? R.drawable.almost_finish_yellow : color.equals("GREEN") ? R.drawable.almost_finish_green : R.drawable.almost_finished_blue, line, column);
		this.color = color;
		
		if (color.equals("RED"))
		{
			this.bluePinImage = R.drawable.almost_finish_red_blue_pin;
			this.blueSuperPinImage = R.drawable.almost_finish_red_blue_super_pin;
			this.greenPinImage = R.drawable.almost_finish_red_green_pin;
			this.greenSuperPinImage = R.drawable.almost_finish_red_green_super_pin;
			this.yellowPinImage = R.drawable.almost_finish_red_yellow_pin;
			this.yellowSuperPinImage = R.drawable.almost_finish_red_yellow_super_pin;
		}
		else if (color.equals("GREEN"))
		{
			this.bluePinImage = R.drawable.almost_finish_green_blue_pin;
			this.blueSuperPinImage = R.drawable.almost_finish_green_blue_super_pin;
			this.redPinImage = R.drawable.almost_finish_green_red_pin;
			this.redSuperPinImage = R.drawable.almost_finish_green_red_super_pin;
			this.yellowPinImage = R.drawable.almost_finish_green_yellow_pin;
			this.yellowSuperPinImage = R.drawable.almost_finish_green_yellow_super_pin;
		}
		else if (color.equals("BLUE"))
		{
			this.redPinImage = R.drawable.almost_finish_blue_red_pin;
			this.redSuperPinImage = R.drawable.almost_finish_blue_red_super_pin;
			this.greenPinImage = R.drawable.almost_finish_blue_green_pin;
			this.greenSuperPinImage = R.drawable.almost_finish_blue_green_super_pin;
			this.yellowPinImage = R.drawable.almost_finish_blue_yellow_pin;
			this.yellowSuperPinImage = R.drawable.almost_finish_blue_yellow_super_pin;
		}
		else
		{
			this.redPinImage = R.drawable.almost_finish_yellow_red_pin;
			this.redSuperPinImage = R.drawable.almost_finish_yellow_red_super_pin;
			this.greenPinImage = R.drawable.almost_finish_yellow_green_pin;
			this.greenSuperPinImage = R.drawable.almost_finish_yellow_green_super_pin;
			this.bluePinImage = R.drawable.almost_finish_yellow_blue_pin;
			this.blueSuperPinImage = R.drawable.almost_finish_yellow_blue_super_pin;
		}
	}
	
	@Override
	public int getDestiny(Pin pin, int diceResult) 
	{
		if (pin.getColor().equals(color))
		{
			return pin.getFinishHouse();
		}
		return this.getNumber();
	}
	@Override
	public void arrivedHere(Pin pin, int diceResult)
	{
		this.setVisitor(pin);
		if (pin.getColor().equals(color))
		{
			pin.jumpTo(pin.getFinishHouse());
			return;
		}		
	}
	@Override
	public int getImage() 
	{
		if (visitor == null)
		{
			return super.getImage();
		}
		if (visitor.getColor().equals("RED"))
		{
			return (visitor instanceof SuperPin) ? redSuperPinImage : redPinImage;
		}
		if (visitor.getColor().equals("GREEN"))
		{
			return (visitor instanceof SuperPin) ? greenSuperPinImage : greenPinImage;
		}
		if (visitor.getColor().equals("BLUE"))
		{
			return (visitor instanceof SuperPin) ? blueSuperPinImage : bluePinImage;
		}
		return (visitor instanceof SuperPin) ? yellowSuperPinImage : yellowPinImage;
	}
}
